package tech.edwardvan.rabbitmqdemo.pattern;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author EdwardVan
 */
public class CommonUtil {
    /**
     * 队列名称
     */
    public static final String QUEUE_WORK = "work_queue";
    public static final String QUEUE_SIMPLE = "simple_queue";
    public static final String QUEUE_PUBLISH_SUBSCRIBE_1 = "publish_subscribe_queue_1";
    public static final String QUEUE_PUBLISH_SUBSCRIBE_2 = "publish_subscribe_queue_2";
    public static final String QUEUE_ROUTING_1 = "routing_queue_1";
    public static final String QUEUE_ROUTING_2 = "routing_queue_2";
    public static final String QUEUE_TOPIC_1 = "topic_queue_1";
    public static final String QUEUE_TOPIC_2 = "topic_queue_2";
    /**
     * 交换机名称
     */
    public static final String EXCHANGE_PUBLISH_SUBSCRIBE = "publish_subscribe_exchange";
    public static final String EXCHANGE_ROUTING = "routing_exchange";
    public static final String EXCHANGE_TOPIC = "topic_exchange";

    /**
     * 生产者消费者名称
     */
    public static final String CONSUMER_1 = "consumer1";
    public static final String CONSUMER_2 = "consumer2";
    public static final String CONSUMER_3 = "consumer3";

    /**
     * 获取Rabbitmq的连接
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        //设置服务地址
        factory.setHost("tech.xyz");

        //AMQP 5672
        factory.setPort(5672);

        //vhost
        factory.setVirtualHost("/");

        //用户名
        factory.setUsername("guest");

        //密码
        factory.setPassword("guest");

        return factory.newConnection();
    }

}
